package com.smashcrush.client.gwt.client.editor;

import java.util.Iterator;

import com.google.gwt.gen2.table.client.MutableTableModel;
import com.google.gwt.gen2.table.client.TableModelHelper.Request;
import com.google.gwt.gen2.table.client.TableModelHelper.Response;
import com.smashcrush.client.gwt.manager.ScriptsManager;
import com.smashcrush.model.Script;

public class ScriptTableModel extends MutableTableModel<Script> {

	@Override
	protected boolean onRowInserted(int beforeRow) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	protected boolean onRowRemoved(int row) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	protected boolean onSetRowValue(int row, Script rowValue) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void requestRows(
			Request request,
			com.google.gwt.gen2.table.client.TableModel.Callback<Script> callback) {

		Response<Script> response = new Response<Script>() {

			@Override
			public Iterator<Script> getRowValues() {
				return ScriptsManager.get().getScripts().iterator();
			}
		};

		callback.onRowsReady(request, response);
	}

}
